package com.example.service.shouye.impl;

import com.example.dao.shouye.ShouyeDao;
import com.example.pojo.Node;
import com.example.pojo.Shouye;
import com.example.service.shouye.ShouyeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class ShouyeServiceImpl implements ShouyeService {
    @Autowired
    private ShouyeDao shouyeDao;

    public List<Node> all(){
        List<Shouye> all = shouyeDao.all();
        List<Node> nodes = get(all, 0);
        return nodes;
    }

    public List<Node> get(List<Shouye> all,int id){
        List<Node> it = new ArrayList<>();
        for (Shouye shouye : all) {
            if(shouye.getWid()==id){
                Node e1 = new Node();
                e1.setId(shouye.getSid());
                e1.setTubiao(shouye.getTubiao());
                e1.setLujing(shouye.getLujing());
                e1.setName(shouye.getSname());
                List<Node> nodes = get(all, shouye.getSid());
                e1.setSubMenus(nodes);
                it.add(e1);
            }
        }
        return it;
    }
}
